package peer.rdp.command;

import peer.share.CacheFileInfo;

public class GetBlockInfoCOM2 extends Command{
	CacheFileInfo bi;
	short biLength;
	byte[] advData;
	String adv;
	public GetBlockInfoCOM2(CacheFileInfo bi){
		this.bi=bi;
		biLength=(short) bi.getByte().length;
		byte[] advData=peer.Config.getAdv().getBytes();
		data=new byte[4+bi.getByte().length+advData.length+2];
		commandType=peer.tools.CommandType.command_QueryBlockInfo2;
		peer.tools.ByteShortSwitch.toByteArray(commandType, data, 0);
		peer.tools.ByteShortSwitch.toByteArray(biLength, data, 2);
		System.arraycopy(bi.getByte(), 0, data, 4, bi.getByte().length);
		peer.tools.ByteShortSwitch.toByteArray((short) advData.length, data, 4+bi.getByte().length);
		System.arraycopy(advData, 0, data, 6+bi.getByte().length,advData.length );
	}
	
	public GetBlockInfoCOM2(byte[] data){
		this.data=data;
		commandType=peer.tools.ByteShortSwitch.toShort(data, 0);
		biLength=peer.tools.ByteShortSwitch.toShort(data, 2);
		byte[] biByte=new byte[biLength];
		System.arraycopy(data, 4, biByte, 0, biLength);
		bi=new CacheFileInfo(biByte);
		int advLength=peer.tools.ByteShortSwitch.toShort(data, 4+bi.getByte().length); 
		advData=new byte[advLength];
		System.arraycopy(data, 6+bi.getByte().length, advData, 0, advData.length);
		adv=new String(advData);
	}
	
	public CacheFileInfo getBi(){
		return bi;
	}
	
	public String getAdv(){
		return adv;
	}
}
